<template>
	<view>
		<tab-nav :tabData="tabData" :tabIndex="tabIndex" @switchStaus="switchStatus"></tab-nav>
		<template v-if="isHasDataFlag">
			<!-- <yy-rec 
				:zxsList="zxsList" 
				:fromPage="fromPage" 
			></yy-rec> -->
			<gy-rec
				:gyList="gyList"
				@goGyDet="goGyDet"
			></gy-rec>
			<loading-view :loading="loading"></loading-view>
		</template>
		<template v-else-if="isHasDataFlag == false">
			<no-data></no-data>
		</template>
	</view>
</template>

<script>
	import TabNav from '@/components/tab-nav/tab-nav.vue'
	import GyRec from './components/GyRec.vue'
	import { getMyGyListZxs } from '@/api/mine/index.js'
	export default {
		components:{
			TabNav,
			GyRec
		},
		data(){
			return{
				tabData:[
					{id:0,name:'全部'},
					{id:1,name:'待干预'},
					{id:2,name:'干预中'},
					{id:3,name:'已完成'}
				],
				tabIndex:0,
				gyStatus:0,
				nowPage:1,
				loading:false,
				hasNextFlag:null,
				isHasDataFlag:null,
				gyList:[],
				fromPage:'gyRec',
				isRefreshFlag:false,
			}
		},
		onLoad(){
			this.getList();
		},
		onShow(){
			if(this.isRefreshFlag){
				this.initParams();
			}
		},
		onHide(){
			this.isRefreshFlag = false;
		},
		onPullDownRefresh : function(){
			this.initParams();
			uni.stopPullDownRefresh();
		},
		onReachBottom : function(){
			if( !this.loading && this.hasNextFlag){
				this.getList();
			}
		},
		methods:{
			getList(){
				let { nowPage,gyList } = this;
				this.loading = true;
				let field = { gyStatus:this.gyStatus,page:this.nowPage,limit:this.limit }
				getMyGyListZxs(field).then(res=>{
					//console.log(res)
					this.hasNextFlag = res.data.hasNext;
					nowPage += 1;
					gyList.push( ...res.data.datas );
					this.gyList = gyList; 
					this.nowPage = nowPage;
					this.loading = false;
					this.isHasDataFlag = true;
				}).catch(err=>{
					//console.log(err)
					this.loading = false;
					this.isHasDataFlag=false;
				});
			},
			switchStatus(index,id){
				this.tabIndex = index;
				this.gyStatus = id;
				this.initParams();
			},
			initParams(){
				this.nowPage = 1;
				this.loading = false;
				this.gyList = [];
				this.getList();
			},
			goGyDet(item){
				uni.navigateTo({
					url:'/pages/subMine/myGy/gyDet?logId=' + item.logId + '&detId=' + item.allotDetailId + '&fromPage=zxsGy&cpTit=' + item.cstTitle
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: $pss-bg-primary;
	}
</style>